home *** CD-ROM | disk | FTP | other *** search
/ Amiga Inside! / Amiga FD Inside (1995)(Ultramax).iso / berndspd / devtools / precognition / demo / lotsogadgets.c < prev    next >
C/C++ Source or Header  |  1994-12-20  |  18KB  |  542 lines

  1. /* =====================================================
  2. **   Created by the Precognition Interface Builder
  3. ** =====================================================
  4. **
  5. **  Link this file with 'Precognition.lib'
  6. **
  7. */
  8.  
  9. #include "Precognition.h"
  10. #include "Intuition_Utils.h"
  11.  
  12. #include <proto/exec.h>
  13. #include <proto/intuition.h>
  14. #include <proto/graphics.h>
  15. #include <stdlib.h>
  16. #include <stdio.h>
  17.  
  18.  
  19. /*
  20. ** The event loop is terminated when 'Done' is true.
  21. */
  22.  
  23. BOOL Done = FALSE;
  24.  
  25. char *cyclegadget3_options[] = 
  26.    {
  27.       "this",
  28.       "that",
  29.       "the other",
  30.       NULL
  31.    };
  32.  
  33.  
  34. struct LotsOgadgets
  35. {
  36.    pcgWindow        w;
  37.    TitleBox            titlebox12;
  38.    OutlineBox        outlinebox13;
  39.    BoolGadget        boolgadget1;
  40.    CheckBox            checkbox2;
  41.    CycleGadget        cyclegadget3;
  42.    StringGadget        stringgadget4;
  43.    IntegerGadget    integergadget5;
  44.    HSlider            hslider6;
  45.    HScroller        hscroller7;
  46.    VSlider            vslider8;
  47.    VScroller        vscroller9;
  48.    ScrollingList    scrollinglist10;
  49.    ListEditor        listeditor11;
  50. };
  51.  
  52.  
  53. /*=============== Prototypes ====================*/
  54.  
  55. #ifdef ANSI_HEADERS
  56.  
  57.    void  LotsOgadgets_Init( 
  58.               struct LotsOgadgets *window,
  59.               struct Screen *screen );
  60.  
  61.    void  LotsOgadgets_CleanUp( struct LotsOgadgets *window );
  62.  
  63.    ULONG LotsOgadgets_Respond( 
  64.               struct LotsOgadgets *window,
  65.               struct IntuiMessage *event );
  66.  
  67.    void  LotsOgadgets_EventLoop( struct Screen *screen );
  68.  
  69.    void  GracefulExit( int ExitStatus );
  70.  
  71. #else
  72.  
  73.    void  LotsOgadgets_Init(); 
  74.    void  LotsOgadgets_CleanUp();
  75.    ULONG LotsOgadgets_Respond();
  76.    void  LotsOgadgets_EventLoop();
  77.    void  GracefulExit();
  78.  
  79. #endif
  80.  
  81.  
  82.  
  83. void LotsOgadgets_Init( window, screen )
  84.    struct LotsOgadgets *window;
  85.    struct Screen *screen;
  86. {
  87.  
  88.    pcg_3DPens    pens;
  89.  
  90.    pens = StandardScreenPens( screen );
  91.  
  92.    /* Initialize the window */
  93.    pcgWindow_Init( &window->w,
  94.       0, 12, 640, 200, /* LeftEdge, TopEdge, Width, Height */
  95.       100, 50, 65535, 65535, /* min width & height, max width & height */
  96.       "application", /* title */
  97.       REFRESHWINDOW | CLOSEWINDOW, /* IDCMPFlags */
  98.       WINDOWSIZING | WINDOWDRAG | WINDOWDEPTH | WINDOWCLOSE | SIZEBBOTTOM | SIMPLE_REFRESH | ACTIVATE, /* Flags */
  99.       screen );
  100.  
  101.    TitleBox_Init( &window->titlebox12,
  102.       360, 20, 160, 20, /* LeftEdge, TopEdge, Width, Height */
  103.       pens, "TitleBox" );
  104.    AddWindowPObject( &window->w, (struct GraphicObject *)&window->titlebox12 );
  105.  
  106.    OutlineBox_Init( &window->outlinebox13,
  107.       193, 128, 109, 28, /* LeftEdge, TopEdge, Width, Height */
  108.       pens, " OutlineBox " );
  109.    AddWindowPObject( &window->w, (struct GraphicObject *)&window->outlinebox13 );
  110.  
  111.    BoolGadget_Init( &window->boolgadget1,
  112.       16, 16, 96, 14, /* LeftEdge, TopEdge, Width, Height */
  113.       pens, "BOOL gadget" );
  114.    AddWindowPObject( &window->w, (struct GraphicObject *)&window->boolgadget1 );
  115.  
  116.    CheckBox_Init( &window->checkbox2,
  117.       20, 36, /* LeftEdge, TopEdge, */
  118.       pens, "CheckMe",
  119.       TRUE ); /* Initially checked? */
  120.    AddWindowPObject( &window->w, (struct GraphicObject *)&window->checkbox2 );
  121.  
  122.    CycleGadget_Init( &window->cyclegadget3,
  123.       68, 60, 96, /* LeftEdge, TopEdge, Width */
  124.       pens, "cycle:", cyclegadget3_options );
  125.    AddWindowPObject( &window->w, (struct GraphicObject *)&window->cyclegadget3 );
  126.  
  127.    StringGadget_Init( &window->stringgadget4,
  128.       68, 88, 112, /* LeftEdge, TopEdge, Width */
  129.       256, /* # of characters */
  130.       pens, "string:" );
  131.    SetStringValue( (Valuator *)&window->stringgadget4, "Hi Mom!" );
  132.    AddWindowPObject( &window->w, (struct GraphicObject *)&window->stringgadget4 );
  133.  
  134.    IntegerGadget_Init( &window->integergadget5,
  135.       72, 112, 48, /* LeftEdge, TopEdge, Width */
  136.       10, /* # of characters */
  137.       pens, "integer:" );
  138.    SetValue( (Valuator *)&window->integergadget5, 42 );
  139.    AddWindowPObject( &window->w, (struct GraphicObject *)&window->integergadget5 );
  140.  
  141.    HSlider_Init( &window->hslider6,
  142.       80, 136, 100, 16, /* LeftEdge, TopEdge, Width, Height */
  143.       pens, "Hslider:" );
  144.    SetKnobSize( (Positioner *)&window->hslider6, 16384 ); /* Knob size */
  145.    SetValue( (Valuator *)&window->hslider6, 32768 ); /* Knob position */
  146.    AddWindowPObject( &window->w, (struct GraphicObject *)&window->hslider6 );
  147.  
  148.    HScroller_Init( &window->hscroller7,
  149.       96, 168, 100, /* LeftEdge, TopEdge, Width */
  150.       pens, "Hscroller:" );
  151.    SetKnobSize( (Positioner *)&window->hscroller7, 16384 ); /* Knob size */
  152.    SetValue( (Valuator *)&window->hscroller7, 32768 ); /* Knob position */
  153.    AddWindowPObject( &window->w, (struct GraphicObject *)&window->hscroller7 );
  154.  
  155.    VSlider_Init( &window->vslider8,
  156.       600, 24, 16, 100, /* LeftEdge, TopEdge, Width, Height */
  157.       pens, "Vslider" );
  158.    SetKnobSize( (Positioner *)&window->vslider8, 16384 ); /* Knob size */
  159.    SetValue( (Valuator *)&window->vslider8, 32768 ); /* Knob position */
  160.    AddWindowPObject( &window->w, (struct GraphicObject *)&window->vslider8 );
  161.  
  162.    VScroller_Init( &window->vscroller9,
  163.       560, 68, 100, /* LeftEdge, TopEdge, Height */
  164.       pens, "Vscroller" );
  165.    SetKnobSize( (Positioner *)&window->vscroller9, 16384 ); /* Knob size */
  166.    SetValue( (Valuator *)&window->vscroller9, 32768 ); /* Knob position */
  167.    AddWindowPObject( &window->w, (struct GraphicObject *)&window->vscroller9 );
  168.  
  169.    ScrollingList_Init( &window->scrollinglist10,
  170.       192, 16, 150, 96, /* LeftEdge, TopEdge, Width, Height */
  171.       pens, FALSE );    /* Allow Selection of >1 item? */
  172.    AddString( (StringLister *)&window->scrollinglist10, "January", 0 );
  173.    AddString( (StringLister *)&window->scrollinglist10, "February", 0 );
  174.    AddString( (StringLister *)&window->scrollinglist10, "March", 0 );
  175.    AddString( (StringLister *)&window->scrollinglist10, "April", 0 );
  176.    AddString( (StringLister *)&window->scrollinglist10, "May", 0 );
  177.    AddString( (StringLister *)&window->scrollinglist10, "June", 0 );
  178.    AddString( (StringLister *)&window->scrollinglist10, "July", 0 );
  179.    AddString( (StringLister *)&window->scrollinglist10, "August", 0 );
  180.    AddString( (StringLister *)&window->scrollinglist10, "September", 0 );
  181.    AddString( (StringLister *)&window->scrollinglist10, "October", 0 );
  182.    AddString( (StringLister *)&window->scrollinglist10, "November", 0 );
  183.    AddString( (StringLister *)&window->scrollinglist10, "December", 0 );
  184.    AddWindowPObject( &window->w, (struct GraphicObject *)&window->scrollinglist10 );
  185.  
  186.    ListEditor_Init( &window->listeditor11,
  187.       380, 68, 150, 96, /* LeftEdge, TopEdge, Width, Height */
  188.       pens, "EditList");
  189.       /*
  190.       ** Add string entries to listeditor11
  191.       */
  192.    AddString( (StringLister*) &window->listeditor11, "Sunday", 0 );
  193.    AddString( (StringLister*) &window->listeditor11, "Monday", 0 );
  194.    AddString( (StringLister*) &window->listeditor11, "Tuesday", 0 );
  195.    AddString( (StringLister*) &window->listeditor11, "Wednesday", 0 );
  196.    AddString( (StringLister*) &window->listeditor11, "Thursday", 0 );
  197.    AddString( (StringLister*) &window->listeditor11, "Friday", 0 );
  198.    AddString( (StringLister*) &window->listeditor11, "Saturday", 0 );
  199.    AddWindowPObject( &window->w, (struct GraphicObject *)&window->listeditor11 );
  200.  
  201. }
  202.  
  203.  
  204. void LotsOgadgets_CleanUp( window )
  205.    struct LotsOgadgets *window;
  206. {
  207.    CleanUp( (struct PObject *)&window->w );
  208.    CleanUp( (struct PObject *)&window->titlebox12 );
  209.    CleanUp( (struct PObject *)&window->outlinebox13 );
  210.    CleanUp( (struct PObject *)&window->boolgadget1 );
  211.    CleanUp( (struct PObject *)&window->checkbox2 );
  212.    CleanUp( (struct PObject *)&window->cyclegadget3 );
  213.    CleanUp( (struct PObject *)&window->stringgadget4 );
  214.    CleanUp( (struct PObject *)&window->integergadget5 );
  215.    CleanUp( (struct PObject *)&window->hslider6 );
  216.    CleanUp( (struct PObject *)&window->hscroller7 );
  217.    CleanUp( (struct PObject *)&window->vslider8 );
  218.    CleanUp( (struct PObject *)&window->vscroller9 );
  219.    CleanUp( (struct PObject *)&window->scrollinglist10 );
  220.    CleanUp( (struct PObject *)&window->listeditor11 );
  221. }
  222.  
  223.  
  224. ULONG LotsOgadgets_Respond( window, event )
  225.      struct LotsOgadgets *window;
  226.      struct IntuiMessage *event;
  227. {
  228.  
  229.    ULONG response, r;
  230.    struct Window *intuition_window;
  231.  
  232.    response = 0L;
  233.  
  234.    /* check to see if 'event' happenned in this window */
  235.    intuition_window = iWindow( &window->w );
  236.    if( event->IDCMPWindow == intuition_window )
  237.    {
  238.       switch( event->Class )
  239.       {
  240.  
  241.          case CLOSEWINDOW:
  242.             pcgCloseWindow( &window->w );
  243.          
  244.             Done =  TRUE; /* Trigger exit of the event loop */
  245.             break;
  246.  
  247.          case REFRESHWINDOW:
  248.             BeginRefresh( intuition_window );
  249.             Refresh( (struct Interactor *)&window->w );
  250.             EndRefresh( intuition_window, TRUE );
  251.             break;
  252.  
  253.          default:
  254.             r = Respond( (struct Interactor *)&window->boolgadget1, event );
  255.             if( r & CHANGED_STATE )
  256.             {  /* boolgadget1 was hit. */
  257.                response |= r;
  258.                ; /* YOUR CODE HERE */
  259.             }
  260.  
  261.             r = Respond( (struct Interactor *)&window->checkbox2, event );
  262.             if( r & CHANGED_STATE )
  263.             { /* checkbox2 was hit. */
  264.                response |= r;
  265.  
  266.                if( Value( (Valuator *)&window->checkbox2 ) ) /* checkbox2 is checked. */
  267.                { 
  268.                   ; /* YOUR CODE HERE */
  269.                }
  270.                else /* checkbox2 is NOT checked. */
  271.                { 
  272.                   ; /* YOUR CODE HERE */
  273.                }
  274.             }
  275.  
  276.             r = Respond( (struct Interactor *)&window->cyclegadget3, event );
  277.             if( r & CHANGED_STATE )
  278.             {  /* cyclegadget3 was cycled.  The current selection 
  279.                ** can be determined by doing:
  280.                **
  281.                **       long v;
  282.                **       v = Value( (Valuator *)&window->cyclegadget3 );
  283.                */
  284.                ; /* YOUR CODE HERE */
  285.                response |= r;
  286.             }
  287.  
  288.             r = Respond( (struct Interactor *)&window->stringgadget4, event );
  289.             if( r & ( CHANGED_STATE | DEACTIVATED ) )
  290.             {  /* User entered something into stringgadget4 
  291.                ** To get the string value of the gadget, use:
  292.                **       char *value;
  293.                **       value = StringValue( (Valuator *)&window->stringgadget4 );
  294.                **
  295.                ** To set the value, use:
  296.                **       SetStringValue( (Valuator *)&window->stringgadget4, value );
  297.                */
  298.                ; /* YOUR CODE HERE */
  299.                /* Activate next string or integer gadget. */
  300.                response |= r;
  301.                ActivateNext( (struct Interactor *)&window->stringgadget4 );
  302.             }
  303.  
  304.             r = Respond( (Interactor *)&window->integergadget5, event );
  305.             if( r & ( CHANGED_STATE | DEACTIVATED ) )
  306.             {  /* User entered something into integergadget5 
  307.                ** To get the value of the gadget, use:
  308.                **       LONG value;
  309.                **       value = Value( (Valuator *)&window->integergadget5 );
  310.                **
  311.                ** To set the value, use:
  312.                **       SetValue( (Valuator *)&window->integergadget5, value );
  313.                */
  314.                ; /* YOUR CODE HERE */
  315.                /* Activate next string or integer gadget. */
  316.                response |= r;
  317.                ActivateNext( (struct Interactor *)&window->integergadget5 );
  318.             }
  319.  
  320.             r = Respond( (Interactor *)&window->hslider6, event );
  321.             if( r & CHANGED_STATE )
  322.             {  /*
  323.                ** HSlider hslider6 has been changed.
  324.                ** 
  325.                ** To read the current value of hslider6, do:
  326.                ** 
  327.                **    USHORT position, knob;
  328.                **    position = (USHORT) Value( (Valuator *)&window->hslider6 );
  329.                **    knob     = KnobSize( (Positioner *)&window->hslider6 );
  330.                */
  331.                ; /* YOUR CODE HERE */
  332.                response |= r;
  333.             }
  334.  
  335.             r = Respond( (Interactor *)&window->hscroller7, event );
  336.             if( r & CHANGED_STATE )
  337.             {  /*
  338.                ** HScroller hscroller7 has been changed.
  339.                ** 
  340.                ** To read the current value of hscroller7, do:
  341.                ** 
  342.                **    USHORT position, knob;
  343.                **    position = (USHORT) Value( (Valuator *)&window->hscroller7 );
  344.                **    knob     = KnobSize( (Positioner *)&window->hscroller7 );
  345.                */
  346.                ; /* YOUR CODE HERE */
  347.                response |= r;
  348.             }
  349.  
  350.             r = Respond( (Interactor *)&window->vslider8, event );
  351.             if( r & CHANGED_STATE )
  352.             {  /*
  353.                ** VSlider vslider8 has been changed.
  354.                ** 
  355.                ** To read the current value of vslider8, do:
  356.                ** 
  357.                **    USHORT position, knob;
  358.                **    position = (USHORT) Value( (Valuator *)&window->vslider8 );
  359.                **    knob     = KnobSize( (Positioner *)&window->vslider8 );
  360.                */
  361.                ; /* YOUR CODE HERE */
  362.                response |= r;
  363.             }
  364.  
  365.             r = Respond( (Interactor *)&window->vscroller9, event );
  366.             if( r & CHANGED_STATE )
  367.             {  /*
  368.                ** VScroller vscroller9 has been changed.
  369.                ** 
  370.                ** To read the current value of vscroller9, do:
  371.                ** 
  372.                **    USHORT position, knob;
  373.                **    position = (USHORT) Value( (Valuator *)&window->vscroller9 );
  374.                **    knob     = KnobSize( (Positioner *)&window->vscroller9 );
  375.                */
  376.                ; /* YOUR CODE HERE */
  377.                response |= r;
  378.             }
  379.  
  380.             r = Respond( (struct Interactor *)&window->scrollinglist10, event );
  381.             if( r & CHANGED_STATE )
  382.             { /* An item was selected. */
  383.                int i;
  384.                char* selected_item;
  385.                StringList  *stringlist;
  386.  
  387.                stringlist = StringList_of( (StringLister *)&window->scrollinglist10);
  388.                for( i = 0; i < stringlist->nEntries; i++ )
  389.                { /* Find selected item(s) */ 
  390.                   if( stringlist->Qualifiers[i] & ENTRY_SELECTED ) 
  391.                   {
  392.                      selected_item = stringlist->Entries[i];
  393.                      /* 'selected_item' is selected. */
  394.                      ; /* YOUR CODE HERE */
  395.                   } 
  396.                }
  397.               response |= r;
  398.             }
  399.  
  400.             r = Respond( (struct Interactor *)&window->listeditor11, event );
  401.             if( r & CHANGED_STATE )
  402.             { /* An item was selected/added/deleted. */
  403.                int i;
  404.                char* selected_item;
  405.                StringList  *stringlist;
  406.  
  407.                stringlist = StringList_of( (StringLister *)&window->listeditor11 );
  408.                for( i = 0; i < stringlist->nEntries; i++ )
  409.                { /* Find selected item(s) */ 
  410.                   if( stringlist->Qualifiers[i] & ENTRY_SELECTED ) 
  411.                   {
  412.                      selected_item = stringlist->Entries[i];
  413.                      /* 'selected_item' is selected. */
  414.                      ; /* YOUR CODE HERE */
  415.                   } 
  416.                }
  417.               response |= r;
  418.             }
  419.  
  420.             break;
  421.  
  422.       } /* end switch */
  423.  
  424.    } /* end if */
  425.  
  426.    return response;
  427. }
  428.  
  429.  
  430. void LotsOgadgets_EventLoop ( screen )
  431.    struct Screen *screen;
  432. {
  433.    struct LotsOgadgets LotsOgadgets;
  434.    struct Window *iw;              /* Intuition window */
  435.    struct IntuiMessage *imsg, event;
  436.    struct MsgPort *userport;
  437.    
  438.    
  439.    LotsOgadgets_Init( &LotsOgadgets, screen );
  440.    
  441.    if( ( iw = pcgOpenWindow( &LotsOgadgets.w ) ) != NULL )
  442.    {
  443.       userport = iw->UserPort;
  444.       
  445.       /*====== Event Loop ================*/
  446.       while( ! Done )
  447.       {
  448.          imsg = WaitForMessage( userport );
  449.          event = *imsg;
  450.          ReplyMsg( (struct Message *) imsg );
  451.          
  452.          LotsOgadgets_Respond( &LotsOgadgets, &event );
  453.          
  454.       }
  455.  
  456.       pcgCloseWindow( &LotsOgadgets.w );
  457.    }
  458.    else /* Error : window couldn't be opened. */
  459.    {
  460.       ; /*** YOUR ERROR HANDLING HERE ***/
  461.    }
  462.  
  463.  
  464.    LotsOgadgets_CleanUp( &LotsOgadgets );
  465. }
  466.  
  467.  
  468. #include <stdio.h>
  469. #include <intuition/screens.h>
  470.  
  471. /* declare lib structures */
  472. struct IntuitionBase *IntuitionBase = NULL;
  473. struct GfxBase       *GfxBase       = NULL;
  474.  
  475. #define HAS_CONSOLE ( argc > 0 )
  476. /*
  477. ** If 'argc' is greater than 0, than the program was started from
  478. ** the command line, and therefore has a console that one can
  479. ** 'fprintf' to.
  480. **
  481. ** If 'argc' == 0, this was started from Workbench.  It's not
  482. ** safe to assume there's a console attached to programs started
  483. ** from Workbench.
  484. */
  485.  
  486. struct Screen *screen;
  487.  
  488. void main ( argc, argv )
  489.    int argc;
  490.    char **argv;
  491. {
  492.   
  493.  
  494.    /* open intuition library */
  495.    IntuitionBase = (struct IntuitionBase *)
  496.       OpenLibrary( "intuition.library", 0 );
  497.    if( IntuitionBase == NULL )
  498.    {
  499.       if( HAS_CONSOLE ) 
  500.          fprintf( stderr, "Error: couldn't open intuition.library\n" );
  501.       GracefulExit( 10 );
  502.    }
  503.  
  504.    GfxBase = (struct GfxBase *)
  505.       OpenLibrary( "graphics.library", 0 );
  506.    if( GfxBase == NULL )
  507.    {
  508.       if( HAS_CONSOLE )
  509.          fprintf( stderr, "Error: couldn't open graphics.library\n" );
  510.       GracefulExit( 20 );
  511.    }
  512.  
  513.    /* Open a screen, if desired. */
  514.  
  515.  
  516.    /* Now do the window event loop. */
  517.    LotsOgadgets_EventLoop( screen );
  518.  
  519.    GracefulExit( 0 );
  520.  
  521. }
  522.  
  523.  
  524. void GracefulExit( int status )
  525. {
  526.    
  527.    if( GfxBase )         
  528.    {
  529.       CloseLibrary( (struct Library*) GfxBase );
  530.       GfxBase = NULL;
  531.    }
  532.  
  533.    if( IntuitionBase )   
  534.    {
  535.       CloseLibrary( (struct Library*) IntuitionBase );
  536.       IntuitionBase = NULL;
  537.    }
  538.  
  539.    exit( status );
  540. }
  541.  
  542.